package com.itheima.ydd.controller;

import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.Config;
import com.itheima.ydd.service.ConfigService;
//import com.sun.org.apache.regexp.internal.RE;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author yan.zhou
 * @date 2022/2/16
 */
@RestController
@RequestMapping("sys_config")
@Slf4j
public class ConfigController {
    /**
     * update   POST    已测
     * all      GET     已测
     */
    @Autowired
    private ConfigService configService;

    @GetMapping("all")
    public ResultData all() {
        Map<String, Object> map = configService.all();
        return ResultData.ok("", map);
    }

    @PostMapping("update")
    public ResultData addConfig(@RequestBody List<Config> configs){
        log.info("修改系统配置:{}",configs);
        if (configs==null) return ResultData.error("数据错误");
        configService.updateBatchById(configs);
        return ResultData.ok("","修改成功");
    }
}